from django.db import models

# Create your models here.
class UserInfo(models.Model):
    """
    用户信息表
    """
    username = models.CharField(max_length=32,unique=True,verbose_name="用户名")
    password = models.CharField(max_length=64)
    create_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name
        db_table = 'UserInfo'



class GuoNei(models.Model):
    """
    国内新闻
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "国内新闻"
        verbose_name_plural = verbose_name
        db_table = 'GuoNei'



class GuoJi(models.Model):
    """
    国际新闻
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "国际新闻"
        verbose_name_plural = verbose_name
        db_table = 'GuoJi'



class JunShi(models.Model):
    """
    TiYu
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "军事新闻"
        verbose_name_plural = verbose_name
        db_table = 'JunShi'



class CaiJing(models.Model):
    """
    财经新闻
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "财经新闻"
        verbose_name_plural = verbose_name
        db_table = 'CaiJing'



class YuLe(models.Model):
    """
    娱乐新闻
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "娱乐新闻"
        verbose_name_plural = verbose_name
        db_table = 'YuLe'



class TiYu(models.Model):
    """
    体育新闻
    """
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "体育新闻"
        verbose_name_plural = verbose_name
        db_table = 'TiYu'



class Search(models.Model):

    user = models.ForeignKey(verbose_name="搜索用户",to="UserInfo")
    title = models.CharField(max_length=255,unique=True,verbose_name="新闻标题")
    url = models.CharField(max_length=255,unique=True,verbose_name="跳转路由")
    time = models.DateTimeField(auto_now=True,verbose_name="更新时间")


    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "搜索新闻"
        verbose_name_plural = verbose_name
        db_table = 'Search'


class Look(models.Model):

    user = models.ForeignKey(verbose_name="用户", to="UserInfo")
    search = models.ForeignKey(verbose_name="新闻", to="Search")

    def __str__(self):

        return self.user.username

    class Meta:
        verbose_name = "浏览新闻"
        verbose_name_plural = verbose_name
        db_table = 'Look'